package com.gateway.filter;

import org.springframework.cloud.gateway.filter.GatewayFilterChain;
import org.springframework.cloud.gateway.filter.GlobalFilter;
import org.springframework.core.Ordered;
import org.springframework.stereotype.Component;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;

/**
 * <dl>
 * <dd>描述: ~ip过滤器</dd>
 * <dd>创建时间：  11:25 2020/5/12</dd>
 * <dd>创建人： zz</dd>
 * <dt>版本历史: </dt>
 * <pre>
 * Date         Author      Version     Description
 * ------------------------------------------------------------------
 * 2020/5/12      guodong       1.0        1.0 Version
 * </pre>
 * </dl>
 */
@Component
public class IpFilter implements GlobalFilter,Ordered{
    @Override
    public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
        //要把ip交给大数据风控部门 ----》 1.http请求发送ip  2.发送mq消息
        String ipPath = exchange.getRequest().getRemoteAddress().getHostName();
        System.out.println("用户访问的ip地址是： " + ipPath);
        return chain.filter(exchange);
    }

    //值越小优先级越高
    @Override
    public int getOrder() {
        return 0;
    }
}
